package eu.dominicum.ra.db4o.outbound;

import javax.resource.ResourceException;
import javax.resource.cci.ConnectionMetaData;

import org.apache.log4j.Logger;

public class Db4oConnectionMetaData implements ConnectionMetaData {
	
	private static final Logger LOG = Logger.getLogger(Db4oConnectionMetaData.class);
	
	private Db4oManagedConnection managedConnection;

	public Db4oConnectionMetaData(Db4oManagedConnection mc) {
	
		LOG.info("Constructing Db4oConnectionMetaData for " + mc);
		
		this.managedConnection = mc;
	}
	
	public String getEISProductName() throws ResourceException {
		return "Db4o Resource Adapter";
	}

	public String getEISProductVersion() throws ResourceException {
		return "1.0M1";
	}

	public String getUserName() throws ResourceException {
		
		if (this.managedConnection.isDestroyed()) {
			throw new ResourceException("This connection is destroyed");
		}
		
		return this.managedConnection.getMetaData().getUserName();
	}

}
